<?
use pft\Member\MemberAccount;//要放在文件的第一行位置
include_once('common/autoload.php');
if(!$_SESSION['memberID']){exit("<script>window.location='dlogin.html'</script>");}
$id=$_REQUEST["id"];
$money=(float)$_REQUEST["money"];
$m_info=$e_info=array();
if(isset($_REQUEST["dname"])){$m_info['dname']=$_REQUEST["dname"];}
if(isset($_REQUEST["cname"])){$m_info['cname']=$_REQUEST["cname"];}
if(isset($_REQUEST["mobile"])){$m_info['mobile']=$_REQUEST["mobile"];}
if(isset($_REQUEST["qq"])){
	$m_info['qq']=$_REQUEST["qq"];
	if(!$m_info['qq']){
		echo "<script>alert(\"请填写QQ,方便联系。\");</script>";
		exit;
	}
}
if(isset($_REQUEST["ctel"])){$m_info['ctel']=$_REQUEST["ctel"];}
if(isset($_REQUEST["alipay"])){$m_info['alipay']=$_REQUEST["alipay"];}
if(isset($_REQUEST["n_accept"])){$m_info['n_accept']=$_REQUEST["n_accept"];}
if(isset($_REQUEST["smsauto"])){$m_info['smsauto']=$_REQUEST["smsauto"];}
if(isset($_REQUEST["smstype"])){$m_info['smstype']=$_REQUEST["smstype"];}
if(isset($_REQUEST["address"])){$m_info['address']=$_REQUEST["address"];}
if(isset($_REQUEST["position"])){$e_info['position']=$_REQUEST["position"];}
if(isset($_REQUEST["sex"])){$e_info['sex']=$_REQUEST["sex"];}
if(isset($_REQUEST["email"])){$e_info['email']=$_REQUEST["email"];}
if(isset($_REQUEST["com_name"])){$e_info['com_name']=$_REQUEST["com_name"];}
if(isset($_REQUEST["com_type"])){
	$e_info['com_type']=$_REQUEST["com_type"]?implode(",",$_REQUEST["com_type"]):"";
}
if(isset($_REQUEST["d_province"])){$e_info['province']=$_REQUEST["d_province"];}
if(isset($_REQUEST["d_city"])){$e_info['city']=$_REQUEST["d_city"];}
if(isset($_REQUEST["fax"])){$e_info['fax']=$_REQUEST["fax"];}
if(isset($_REQUEST["website"])) {
    $e_info['website']=$_REQUEST["website"];
}
if(isset($_REQUEST["business"])){
    $e_info['business']=$_REQUEST["business"];
}
if(isset($_REQUEST["bsn_les"])) {$e_info['bsn_les']=$_REQUEST["bsn_les"];}
if(isset($_REQUEST["opt_les"])) {$e_info['opt_les']=$_REQUEST["opt_les"];}
if(isset($_REQUEST["id_card"])){
    $e_info['id_card']=$_REQUEST["id_card"];
}
if(isset($_REQUEST["short_company_name"])){
    $e_info['short_company_name']=$_REQUEST["short_company_name"]=="最多4个字"?"":$_REQUEST["short_company_name"];
}
$tt = $_REQUEST['tt'];
if ($tt){
    $logo=$_FILES[$tt];
}

if($logo["size"]){
	$type=array("image/gif","image/jpeg","image/pjpeg","image/png","image/x-png");
	$maxsize=2000000;
		
	if($_SERVER['REQUEST_METHOD']=="POST"){

		if (in_array($logo["type"],$type) && ($logo["size"] < $maxsize)) {
			if ($logo["error"] > 0){
				echo $logo["error"];
			}
			else{

				$sel="select account from pft_member where id=".$_SESSION['sid']." limit 1";
				$GLOBALS['le']->query($sel);
				$GLOBALS['le']->fetch_assoc();
				$passport=$GLOBALS['le']->f("account");
				//生成存储路径
				$dir="upload/".$passport;
				if(!is_dir($dir)){
					mkdir($dir);
                    chmod($dir, 0777);
				}
                if (!is_writable($dir)) {
                    @chmod($dir, 0777);
                }
				$fileinfo=pathinfo($logo["name"]);
				$filetype=$fileinfo['extension'];
				$dir.="/".$_SERVER['REQUEST_TIME'].".".$filetype;
				//截取图片	
				list($width_orig, $height_orig) = getimagesize($logo["tmp_name"]);
				$star_x=0;//源的 X 坐标点
				$star_y=0;//源的 Y 坐标点
				$copy_width=$width_orig;//源图象的宽度
				$copy_height=$height_orig;//源图象的高度
				$width=$width_orig;//目标宽度
				$height=$height_orig;//目标高度
				
				$image_p = imagecreatetruecolor($width, $height);

				switch($logo["type"]){
					case "image/pjpeg": 
						$image = imagecreatefromjpeg($logo["tmp_name"]);
						imagecopyresampled($image_p, $image, 0, 0, $star_x, $star_y, $width, $height, $copy_width, $copy_height); 
						imagejpeg($image_p, $dir, 100);
						break;
					case "image/jpeg":
						$image = imagecreatefromjpeg($logo["tmp_name"]);
						imagecopyresampled($image_p, $image, 0, 0, $star_x, $star_y, $width, $height, $copy_width, $copy_height); 
						imagejpeg($image_p, $dir, 100);
						break;
					case "image/gif":
						$image = imagecreatefromgif($logo["tmp_name"]);
						imagecopyresampled($image_p, $image, 0, 0, $star_x, $star_y, $width, $height, $copy_width, $copy_height); 
						imagegif($image_p, $dir, 100);
						break; 
					case "image/x-png":
						$image = imagecreatefrompng($logo["tmp_name"]);
						$alpha = imagecolorallocatealpha($image_p, 0, 0, 0, 127);
						imagefill($image_p, 0, 0, $alpha);
						imagecopyresampled($image_p, $image, 0, 0, $star_x, $star_y, $width, $height, $copy_width, $copy_height);
						imagesavealpha($image_p, true);
						imagepng($image_p, $dir, 9);
						break; 	
					case "image/png":
						$image = imagecreatefrompng($logo["tmp_name"]);
						$alpha = imagecolorallocatealpha($image_p, 0, 0, 0, 127);
						imagefill($image_p, 0, 0, $alpha);
						imagecopyresampled($image_p, $image, 0, 0, $star_x, $star_y, $width, $height, $copy_width, $copy_height);
						imagesavealpha($image_p, true);
						imagepng($image_p, $dir, 9);
						break; 	  
				}
				if($tt=="headphoto")$m_info[$tt]="/".$dir;
				else $e_info[$tt]="/".$dir;
			}
		}
		else{
			echo "<script>alert(\"上传文件类型不合法或过大!\");</script>";
			exit;
		}
	}
	else{
		echo "<script>alert(\"传输类型非POST!\");</script>";
		exit;
	}
}
if($money!=0){
	if(($res=$s->PFT_Member_Fund_Modify((int)$_SESSION['memberID'],(int)$_SESSION['memberID'],(abs($money)*100),($money>0?1:0),0,"",3,0))==100){
		if(($res=$s->PFT_Member_Fund_Modify((int)$id,(int)$_SESSION['memberID'],(abs($money)*100),($money>0?0:1),0,"",3,0))!=100){
			echo "<script>alert('充值出错:".$res."');</script>";
			exit;
		}
	}
}
$mem = new MemberAccount($GLOBALS['le']);//实例化时需要注入mysql连接标识
$res=$mem->update($id, $m_info, $e_info);
if($res['status']=="ok"){
	if(isset($_REQUEST["dname"]) && $id==$_SESSION['memberID']){$_SESSION['dname']=$_REQUEST["dname"];}
	echo "<script>alert('修改成功!');parent.window.location=window.parent.location.href;</script>";
	exit;
}
else{
	echo "<script>alert(\"".$res['msg']."\")</script>";
}
?>